package de.baumann.browser;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class OdinGlideModule extends AppGlideModule {
    public static void load(Context context, String path, ImageView imageView, int drawable) {
        if (drawable != 0) {
            GlideApp.with(context)
                    .load(path)
                    .placeholder(drawable)
                    .error(drawable)
                    .dontAnimate()
                    .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                    .into(imageView);
        } else {
            GlideApp.with(context).load(path)
                    .dontAnimate()
                    .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                    .into(imageView);
        }
    }


    public static void loadWithRoundedCorners(Context context, String path, ImageView imageView, int drawable) {
            GlideApp.with(context)
                    .load(path)
                    .centerCrop()
                    .placeholder(drawable)
                    .transform(new RoundedCorners(15))
                    .error(drawable)
                    .into(imageView);
    }

    public static void loadWithCrop(Context context, String path, ImageView imageView, int drawable) {
        if (drawable != 0) {
            GlideApp.with(context)
                    .load(path)
                    .centerCrop()
                    .placeholder(drawable)
                    .error(drawable)
                    .into(imageView);
        } else {
            GlideApp.with(context)
                    .load(path)
                    .centerCrop()
                    .into(imageView);
        }
    }


    public static void loadWithCropAndCircle(Context context, String path, ImageView imageView, int drawable) {
        if (drawable != 0) {
            GlideApp.with(context).load(path).centerCrop().circleCrop().placeholder(drawable).error(drawable).into(imageView);
        } else {
            GlideApp.with(context).load(path).centerCrop().circleCrop().into(imageView);
        }
    }

}
